from random import randint
from time import sleep
from selenium import webdriver
from selenium.webdriver.support.select import Select

driver = webdriver.Firefox()
driver.get('http://localhost/bajiusi/index.asp')
sleep(2)
list1 = driver.find_elements_by_tag_name('input')
list1[0].send_keys('admin')
list1[1].send_keys('admin')
list1[2].click()
sleep(1)

driver.switch_to.frame('left')
xt_css = '.menuall > tbody:nth-child(1) > tr:nth-child(13) > td:nth-child(1)'
driver.find_element_by_css_selector(xt_css).click()
sleep(1)
dw_css = '#g_6 > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(7) > td:nth-child(1)'
driver.find_element_by_css_selector(dw_css).click()
sleep(1)

driver.switch_to.default_content()
driver.switch_to.frame('right')
sleep(1)
driver.find_element_by_name('chkall').click()
sc_css = 'input.button:nth-child(2)'
driver.find_element_by_css_selector(sc_css).click()
driver.switch_to.alert.accept()
tj_css = 'input.button:nth-child(1)'
driver.find_element_by_css_selector(tj_css).click()
sleep(1)

driver.find_element_by_name('danwei').send_keys('kg')
driver.find_element_by_name('submit').click()
sleep(1)
driver.switch_to.alert.accept()
sleep(1)

driver.switch_to.default_content()
driver.switch_to.frame('left')
dl_css = '#g_6 > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(5) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2)'
driver.find_element_by_css_selector(dl_css).click()

driver.switch_to.default_content()
driver.switch_to.frame('right')
sleep(1)
driver.find_element_by_css_selector(tj_css).click()

driver.find_element_by_name('bigclass').send_keys('70')
driver.find_element_by_name('submit').click()
sleep(1)
driver.switch_to.alert.accept()
sleep(1)

driver.switch_to.default_content()
driver.switch_to.frame('left')
xl_css = '#g_6 > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(6) > td:nth-child(1) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2)'
driver.find_element_by_css_selector(xl_css).click()

driver.switch_to.default_content()
driver.switch_to.frame('right')
sleep(1)
driver.find_element_by_css_selector(tj_css).click()

sel_lst = Select(driver.find_element_by_name('bigclass'))
lst_count = len(sel_lst.options)
rand = randint(0, lst_count-1)
sel_lst.select_by_index(rand)
driver.find_element_by_name('smallclass').send_keys('6')
driver.find_element_by_name('submit').click()
sleep(1)
driver.switch_to.alert.accept()
sleep(1)

driver.switch_to.default_content()

driver.switch_to.frame('topFrame')
driver.find_element_by_link_text('安全退出').click()
sleep(1)
driver.switch_to.alert.accept()
sleep(1)
driver.quit()